import request from '@/utils/request'

/**
 * 上传项目附件
 * @param {number} relatedId - 关联项目ID
 * @param {string} relatedType - 关联类型 (如: teaching_project)
 * @param {FormData} formData - 文件数据
 */
export function uploadProjectAttachment(relatedId, relatedType, formData) {
    formData.append('relatedId', relatedId)
    formData.append('relatedType', relatedType)

    return request({
        url: '/upload/attachment',
        method: 'post',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

/**
 * 获取附件列表
 * @param {string} relatedType - 关联类型
 * @param {number} relatedId - 关联ID
 */
export function getAttachments(relatedType, relatedId) {
    return request({
        url: '/upload/attachments',
        method: 'get',
        params: { relatedType, relatedId }
    })
}

/**
 * 删除附件
 * @param {number} attachmentId - 附件ID
 */
export function deleteAttachment(attachmentId) {
    return request({
        url: `/upload/attachment/${attachmentId}`,
        method: 'delete'
    })
}

/**
 * 下载附件
 * @param {number} attachmentId - 附件ID
 */
export function downloadAttachment(attachmentId) {
    return request({
        url: `/upload/attachment/${attachmentId}/download`,
        method: 'get',
        responseType: 'blob'
    })
}